package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.LeaveType;
import com.ruoyi.system.service.ILeaveTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 请假类型Controller
 * 
 * @author ruoyi
 * @date 2022-09-24
 */
@RestController
@RequestMapping("/out/leaveType")
public class LeaveTypeController extends BaseController
{
    @Autowired
    private ILeaveTypeService leaveTypeService;

    /**
     * 查询请假类型列表
     */
    @PreAuthorize("@ss.hasPermi('out:leaveType:list')")
    @GetMapping("/list")
    public TableDataInfo list(LeaveType leaveType)
    {
        startPage();
        List<LeaveType> list = leaveTypeService.selectLeaveTypeList(leaveType);
        return getDataTable(list);
    }

    /**
     * 导出请假类型列表
     */
    @PreAuthorize("@ss.hasPermi('out:leaveType:export')")
    @Log(title = "请假类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LeaveType leaveType)
    {
        List<LeaveType> list = leaveTypeService.selectLeaveTypeList(leaveType);
        ExcelUtil<LeaveType> util = new ExcelUtil<LeaveType>(LeaveType.class);
        util.exportExcel(response, list, "请假类型数据");
    }

    /**
     * 获取请假类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('out:leaveType:query')")
    @GetMapping(value = "/{leaveId}")
    public AjaxResult getInfo(@PathVariable("leaveId") String leaveId)
    {
        return AjaxResult.success(leaveTypeService.selectLeaveTypeByLeaveId(leaveId));
    }

    /**
     * 新增请假类型
     */
    @PreAuthorize("@ss.hasPermi('out:leaveType:add')")
    @Log(title = "请假类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeaveType leaveType)
    {
        return toAjax(leaveTypeService.insertLeaveType(leaveType));
    }

    /**
     * 修改请假类型
     */
    @PreAuthorize("@ss.hasPermi('out:leaveType:edit')")
    @Log(title = "请假类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeaveType leaveType)
    {
        return toAjax(leaveTypeService.updateLeaveType(leaveType));
    }

    /**
     * 删除请假类型
     */
    @PreAuthorize("@ss.hasPermi('out:leaveType:remove')")
    @Log(title = "请假类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{leaveIds}")
    public AjaxResult remove(@PathVariable String[] leaveIds)
    {
        return toAjax(leaveTypeService.deleteLeaveTypeByLeaveIds(leaveIds));
    }
}
